﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMLSpreadGear.Headers;

namespace XMLSpreadGear.Presentation
{
    public abstract class BasePresentationStyle
    {
        private Styles _styles;
        public const string ColumnStyleID = "colstyle";
        public const string CellStyleID = "cellStyle";
        public const string DateCellStyleID = "cellStyledt";
        public const string HeaderStyleID = "headerstyle";
        public const string SubHeaderStyleID = "subheaderstyle";
        public const string FooterStyleID = "footerstyle";
        public const string NumberCellStyleID = "numcellstyle";

        public BasePresentationStyle()
        {
            _styles = GenerateStyle();
        }

        public abstract string GetInteriorColorName();

        public abstract string GetInteriorFontColorName();

        public abstract string GetHeaderInteriorColorName();

        public abstract string GetHeaderInteriorFontColorName();

        public abstract string GetSubHeaderInteriorColorName();

        public abstract string GetSubHeaderInteriorFontColorName();

        public virtual string NumberFormat()
        {
            return string.Empty;
        }
        
        private Styles GenerateStyle()
        {
            Styles styles = new Styles();
            styles.Style = new Style("Default");

            Style colstyle = new Style(ColumnStyleID);
            colstyle.Interior = new Interior();
            colstyle.Interior.Pattern = XMLSpreadGear.Core.InteriorPattern.Solid;
            colstyle.Interior.Color = GetInteriorColorName();
            colstyle.Font = new XMLSpreadGear.Headers.Font();
            colstyle.Font.Bold = true;
            colstyle.Font.Color = GetInteriorFontColorName();
            colstyle.Font.Size = 10.0;
            colstyle.Borders = new Borders();
            colstyle.Borders.Border = new Border(XMLSpreadGear.Core.Position.Top);
            colstyle.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Top) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });
            colstyle.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Right) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });
            colstyle.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Left) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });
            colstyle.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Bottom) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });
            styles.Style.Add(colstyle);



            Style celstyle = new Style(CellStyleID);
            celstyle.Font = new XMLSpreadGear.Headers.Font();
            celstyle.Font.Size = 8.0;
            celstyle.Borders = new Borders();
            celstyle.Borders.Border = new Border(XMLSpreadGear.Core.Position.Top);
            celstyle.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Top) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });
            celstyle.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Right) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });
            celstyle.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Left) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });
            celstyle.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Bottom) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });

            styles.Style.Add(celstyle);


            Style celstyledt = new Style(DateCellStyleID);
            celstyledt.Font = new XMLSpreadGear.Headers.Font();
            celstyledt.Font.Size = 8.0;
            celstyledt.Borders = new Borders();
            celstyledt.Borders.Border = new Border(XMLSpreadGear.Core.Position.Top);
            celstyledt.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Top) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });
            celstyledt.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Right) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });
            celstyledt.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Left) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });
            celstyledt.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Bottom) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });
            celstyledt.Alignment = new StyleAlignment();
            celstyledt.Alignment.AlignmentHorizontal = XMLSpreadGear.Core.HorizontalAlignment.Right;
            styles.Style.Add(celstyledt);


            Style celstylenum = new Style(NumberCellStyleID);
            celstylenum.Font = new XMLSpreadGear.Headers.Font();
            celstylenum.Font.Size = 8.0;
            celstylenum.Borders = new Borders();
            celstylenum.Borders.Border = new Border(XMLSpreadGear.Core.Position.Top);
            celstylenum.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Top) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });
            celstylenum.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Right) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });
            celstylenum.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Left) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });
            celstylenum.Borders.Border.Add(new Border(XMLSpreadGear.Core.Position.Bottom) { LineStyle = XMLSpreadGear.Core.LineStyle.Continuous, Weight = 1.0, Color = GetInteriorColorName() });
            celstylenum.Alignment = new StyleAlignment();
            celstylenum.Alignment.AlignmentHorizontal = XMLSpreadGear.Core.HorizontalAlignment.Right;
            
            if(NumberFormat() != string.Empty)
                celstylenum.NumberFormat = new NumberFormat(NumberFormat());    

            styles.Style.Add(celstylenum);


            Style headerstyle = new Style(HeaderStyleID);
            headerstyle.Interior = new Interior();
            headerstyle.Interior.Pattern = XMLSpreadGear.Core.InteriorPattern.Solid;
            headerstyle.Interior.Color = GetHeaderInteriorColorName();
            headerstyle.Font = new XMLSpreadGear.Headers.Font();
            headerstyle.Font.Bold = true;
            headerstyle.Font.Color = GetHeaderInteriorFontColorName();
            headerstyle.Font.FontName = "Arial";
            headerstyle.Font.Size = 16.0;
            headerstyle.Alignment = new StyleAlignment();
            headerstyle.Alignment.AlignmentHorizontal = XMLSpreadGear.Core.HorizontalAlignment.Center;
            styles.Style.Add(headerstyle);


            Style subheaderstyle = new Style(SubHeaderStyleID);
            subheaderstyle.Interior = new Interior();
            subheaderstyle.Interior.Pattern = XMLSpreadGear.Core.InteriorPattern.Solid;
            subheaderstyle.Interior.Color = GetSubHeaderInteriorColorName();
            subheaderstyle.Font = new XMLSpreadGear.Headers.Font();
            subheaderstyle.Font.Bold = true;
            subheaderstyle.Font.Color = GetSubHeaderInteriorFontColorName();
            subheaderstyle.Font.FontName = "Arial";
            subheaderstyle.Font.Size = 12.0;
            subheaderstyle.Alignment = new StyleAlignment();
            subheaderstyle.Alignment.AlignmentHorizontal = XMLSpreadGear.Core.HorizontalAlignment.Center;
            styles.Style.Add(subheaderstyle);


            Style footerstyle = new Style(FooterStyleID);
            footerstyle.Font = new XMLSpreadGear.Headers.Font();
            footerstyle.Font.Bold = true;
            footerstyle.Font.Size = 6;
            styles.Style.Add(footerstyle);

            return styles;
        }

        public Styles Style
        {
            get { return _styles; }
        }
    }
}
